package jsen.tool.ddd.demo.domain.parking.spec.parking;

import jsen.tool.ddd.adapter.infrastructure.specification.ISpecification;
import jsen.tool.ddd.adapter.infrastructure.specification.base.SpecContext;
import jsen.tool.ddd.demo.domain.parking.ParkingStatus;

/**
 * @author jsen
 * @date 2021/10/6
 */
public class ParkingStatusSpec implements ISpecification<ParkingStatus> {
    @Override
    public boolean isSatisfiedBy(SpecContext<ParkingStatus> t) {
        ParkingStatus status = t.getData();
        if (status.getStartTime() != null && status.getEndTime() != null && status.getStartTime() > status.getEndTime()) {
            t.addError("ParkingStatus", "停车记录状态错误");
            return false;
        }
        return true;
    }
}
